from PyQt5.QtCore import QUrl, QObject, pyqtSlot
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQuick import QQuickView

class MyClass(QObject):
    @pyqtSlot(str)    # 输入参数为str类型
    def outputString(self, string):
        print(string)

class MyQuickView(QQuickView):
    def __init__(self, reactor, *args, **kw):
        super().__init__(*args, **kw)
        self.reactor = reactor

    def closeEvent(self, e):
        print('Exit')
        self.reactor.stop()

if __name__ == '__main__':
    path = 'room.qml'   # 加载的QML文件
    app = QGuiApplication([])
    import qt5reactor
    qt5reactor.install()
    from twisted.internet import reactor
    view = QQuickView()
    con = MyClass()
    context = view.rootContext()
    context.setContextProperty("con", con)
    view.engine().quit.connect(app.quit)
    view.setSource(QUrl(path))
    view.show()
    app.exec_()
    reactor.runReturn()
